﻿@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="topPanel">
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a id="NF-Add" class="btn btn-primary" onclick="btn_add()"><i class="fa fa-plus"></i>新增区域</a>
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
                <li><a id="NF-Edit" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>编辑区域</a></li>
                <li><a id="NF-Details" onclick="btn_details()"><i class="fa fa-pencil-square-o"></i>查看区域</a></li>
                <li><a id="NF-Delete" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除区域</a></li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
</div>
<script>
    $(function () {
        gridList();
    })
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            treeGrid: true,
            treeGridModel: "adjacency",
            ExpandColumn: "EnCode",
            url: "/SystemManage/Region/GetTreeGridJson",
            height: $(window).height() - 96,
            colModel: [
                { label: "主键", name: "Id", hidden: true, key: true, sortable: false },
                { label: '名称', name: 'FullName', width: 150, align: 'left', sortable: false},
                { label: '编码', name: 'EnCode', width: 50, align: 'center', sortable: false },
                { label: '简称', name: 'ShortName', width: 50, align: 'center', sortable: false },
                { label: '聚合名称', name: 'MergerName', width: 200, align: 'left', sortable: false },
                { label: '层级', name: 'Layers', width: 50, align: 'center', sortable: false },
                { label: '城市编码', name: 'CityCode', width: 50, align: 'center', sortable: false },
                { label: '邮政编码', name: 'ZipCode', width: 50, align: 'center', sortable: false },
                { label: '经度', name: 'Longitude', width: 50, align: 'center', sortable: false },
                { label: '纬度', name: 'Latitude', width: 50, align: 'center', sortable: false },
                { label: '全拼', name: 'FullSpell', width: 50, align: 'center', sortable: false },
                { label: '首拼', name: 'FirstSpell', width: 50, align: 'center', sortable: false },
            ]
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
        $('#txt_keyword').bind('keyup', function (event) {
            if (event.keyCode == "13") {
                //回车执行查询
                $("#btn_search").click();
            }
        });
    }
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增区域",
            url: "/SystemManage/Region/Form",
            width: "700px",
            height: "400px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        $.modalOpen({
            id: "Form",
            title: "编辑区域",
            url: "/SystemManage/Region/Form?keyValue=" + keyValue,
            width: "700px",
            height: "400px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_details() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        $.modalOpen({
            id: "Form",
            title: "查看区域",
            url: "/SystemManage/Region/Details?keyValue=" + keyValue,
            width: "700px",
            height: "400px",
            btn: null
        });
    }
    function btn_delete() {
        var rowData = $("#gridList").jqGridRowValue();
        if (rowData.isLeaf == 'false') {
            $.modalAlert('注：该数据项下还包含有叶子节点，不能直接删除！', 'warning');
            return false;
        }
        $.deleteForm({
            url: "/SystemManage/Region/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().Id },
            success: function () {
                $.currentWindow().$("#gridList").resetSelection();
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
</script>